package deployr.core;

import static java.text.MessageFormat.*;

public class JettyContextXml {

	private final StringBuilder xml = new StringBuilder();

	public JettyContextXml(String appId) {
		append("<?xml version=\"1.0\"  encoding=\"ISO-8859-1\"?>");
		append("<!DOCTYPE Configure PUBLIC \"-//Mort Bay Consulting//DTD Configure//EN\" \"http://jetty.mortbay.org/configure.dtd\">");
		append("<Configure class=\"org.mortbay.jetty.webapp.WebAppContext\">");
		append("  <Set name=\"contextPath\">/{0}</Set>", appId);
		append("  <Set name=\"war\"><SystemProperty name=\"jetty.home\" default=\".\"/>/workspaces/{0}/webapps/{1}.war</Set>", "user", appId);
		append("</Configure>");
	}

	private void append(String string, String... args) {
		xml.append(format(string, args)).append("\n");
	}

	public byte[] getBytes() {
		return xml.toString().getBytes();
	}

}
